package cn.mengfly.testnrz.im.client.bean;

import cn.mengfly.testnrz.im.ProtoMsg;
import lombok.Data;

@Data
public class ChatMsg {
    public enum MsgType {
        /**
         * 纯文本
         */
        TEXT,
        /**
         * 音频
         */
        AUDIO,
        /**
         * 视频
         */
        VIDEO,
        /**
         * 地理位置
         */
        POS,
        /**
         * 其他
         */
        OTHER
    }

    private User user;
    private long msgId;
    private String from;
    private String to;
    private long time;
    private MsgType msgType;
    private String content;
    /**
     * 多媒体地址
     */
    private String url;
    /**
     * 附加属性
     */
    private String property;
    /**
     * 发送者昵称
     */
    private String fromNick;
    /**
     * 附加的json串
     */
    private String json;

    public ChatMsg(User user) {
        if (null == user) {
            return;
        }
        this.user = user;
        setTime(System.currentTimeMillis());
        setFrom(user.getUid());
        setFromNick(user.getNickName());
    }

    public void fillMsg(ProtoMsg.MessageRequest.Builder cb) {
        if (msgId > 0) {
            cb.setMsgId(msgId);
        }
        if (StringUtil.isNotEmpty(from)) {
            cb.setFrom(from);
        }
        if (StringUtil.isNotEmpty(to)) {
            cb.setTo(to);
        }
        if (time > 0) {
            cb.setTime(time);
        }
        if (msgType != null) {
            cb.setMsgType(msgType.ordinal());
        }
        if (StringUtil.isNotEmpty(content)) {
            cb.setContent(content);
        }
        if (StringUtil.isNotEmpty(url)) {
            cb.setUrl(url);
        }
        if (StringUtil.isNotEmpty(property)) {
            cb.setProperty(property);
        }
        if (StringUtil.isNotEmpty(fromNick)) {
            cb.setFromNick(fromNick);
        }
        if (StringUtil.isNotEmpty(json)) {
            cb.setJson(json);
        }
    }

}
